﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Security;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using GmailMetroNotifier.Client.UI.Foundation;

namespace GmailMetroNotifier.Client.UI
{
    /// <summary>
    /// Authentication form used to capture credential information.
    /// </summary>
    public partial class AuthenticationForm : SystemForm
    {
        /// <summary>
        /// Gets the credential input by the user.
        /// </summary>
        public NetworkCredential Credentials { get; private set; }

        /// <summary>
        /// Initializes a new instance.
        /// </summary>
        public AuthenticationForm() : base()
        {
            InitializeComponent();

            this.Credentials = new NetworkCredential();
        }

        /// <summary>
        /// Initializes a new instance which shows the given username by default.
        /// </summary>
        /// <param name="userName">The username to show by default.</param>
        public AuthenticationForm(string userName) : this()
        {
            this.usernameTextBox.Text = userName;
        }

        private void acceptButton_Click(object sender, EventArgs e)
        {
            SecureString securePassword = new SecureString();
            
            foreach (char passwordChar in this.passwordTextBox.Text)
            {
                securePassword.AppendChar(passwordChar);
            }

            this.Credentials.UserName = this.usernameTextBox.Text;
            this.Credentials.SecurePassword = securePassword;
        }
    }
}
